<?php

require("config.php");

/*
1 - 私密
2 - 仅好友
5 - 仅登录用户
10 - 公开
*/

$pageno = get_get("page");
if (is_logon()) {
	$result = $db->query("select count(*) as count from po_blog where status>=0 and username='%s' or visible>=5", $user['username']);
} else {
	$result = $db->query("select count(*) as count from po_blog where status>=0 and visible>=10");
}
if ($result) {
	$row = $db->fetch_assoc($result);
	$pagecount = $row['count'];
} else {
	echo "db error";
	exit;
}

$page = paging("blog.php?page=", $pagecount, $pageno);
if (is_logon()) {
	$result = $db->query("select * from po_blog where status>=0 and username='%s' or visible>=5 order by id desc limit %d,%d",$user['username'], $page['start'], $page['perpage']);
} else {
	$result = $db->query("select * from po_blog where status>=0 and visible>=10 order by id desc limit %d,%d", $page['start'], $page['perpage']);
}

page_common("博客");
$t->set_file("body", "blog.html");
$t->set_var("T_PAGING", $page['html']);
$t->set_block("body", "row", "aaa");
if ($result) {
	while (($row = $db->fetch_assoc($result))) {
		$t->set_var("T_TITLE", $row['title']);
		$t->set_var("T_OWNER", $row['username']);
		$t->set_var("T_ADDTIME", $row['addtime']);
		$t->set_var("T_TAGS", tag_links($row['tags']));
		$t->set_var("T_CONTENT", format_content($row['content']));
		$t->parse("aaa", "row", true);
	}
}

$t->pparse("out", "body");

